package com.csun.cmny.provider.controller;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.OmcCurTaskQueryGroup;
import com.csun.cmny.provider.model.dto.OmcCurTaskQueryDto;
import com.csun.cmny.provider.model.vo.query.CurTaskQueryVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OmcCurTaskQueryGroupService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-10-12 14:57
 * @Description:
 */
@RestController
@RequestMapping(value = "/curTaskQueryGroup", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class OmcCurTaskQueryGroupController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private OmcCurTaskQueryGroupService omcCurTaskQueryGroupService;

    /**
     * 查询
     */
    @PostMapping(value = "/queryCurTaskQueryGroupListWithPage")
    public Wrapper queryCurTaskQueryGroupListWithPage(@RequestBody OmcCurTaskQueryDto omcCurTaskQueryDto) {

        if (omcCurTaskQueryDto.getGroupId() == null) {
            omcCurTaskQueryDto.setGroupId(getLoginAuthDto().getGroupId());
        }

        List<CurTaskQueryVo> curTaskQueryVoList = omcCurTaskQueryGroupService
                .queryCurTaskQueryGroupListWithPage(omcCurTaskQueryDto);

//        return WrapMapper.ok(new PageInfo<>(curTaskQueryVoList));
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource.getMessage("operation.success", null), new PageInfo<>(curTaskQueryVoList));
    }

    /**
     * 绑定
     */
    @PostMapping(value = "/bind")
    public Wrapper bind(@RequestBody OmcCurTaskQueryGroup omcCurTaskQueryGroup) {

        Integer result = omcCurTaskQueryGroupService.bind(omcCurTaskQueryGroup);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

//        return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource.getMessage("operation.success", null), result);
    }

    /**
     * 解绑
     */
    @PostMapping(value = "/untied")
    public Wrapper untied(@RequestBody OmcCurTaskQueryGroup omcCurTaskQueryGroup) {

        Integer result = omcCurTaskQueryGroupService.untied(omcCurTaskQueryGroup);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

//        return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource.getMessage("operation.success", null), result);
    }

}
